package com.temple.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.comon.core.domain.result.R;
import com.comon.core.enums.ResultCode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.temple.model.card.CardInfo;
import com.temple.model.card.DTO.CardInfoDTO;
import com.temple.model.card.DTO.CardNewInfo;
import com.temple.model.card.DTO.SelfTieZiDTO;
import com.temple.service.card.CardService;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-09-12
 * Time:12:16
 * Text：
 */
@RestController
@Tag(name="殿堂注册API")
public class CardController {
    @Autowired
    CardService cardService;
    @Autowired
    private ObjectMapper objectMapper;
    @PostMapping("/createTieZi")
    public R<?> CreateTieZi(@RequestParam(value = "files[]", required = false) List<MultipartFile> files,
                            @RequestPart("cardInfoDTO") String cardInfoDTO, HttpServletRequest request) throws IOException {
        Long Uid = Long.parseLong(request.getSession().getAttribute("UserId").toString());
        CardInfoDTO cardInfoDTO1 = objectMapper.readValue(cardInfoDTO,CardInfoDTO.class);
        return cardService.CreateTieZi(Uid,cardInfoDTO1,files);
    }
    @PostMapping("/publicPicture")
    public R<?> publicPicture(@RequestParam("files[]") List<MultipartFile> files,
                              @RequestPart("cardCirid") String cardCirid,
                            HttpServletRequest request) throws IOException {
        Long Uid = Long.parseLong(request.getSession().getAttribute("UserId").toString());
        return cardService.publicPicture(Uid,cardCirid,files);
    }



    @GetMapping("/GetNewTieZi/{start}")
    public R<?> getTieZi(@PathVariable int start) {
        return cardService.getNewTieZi(start);
    }



    @GetMapping("/getTemple/{cir_id}")
    public R<?> getTieZis(@PathVariable int cir_id){
        return null;
    }

    @PostMapping("/getSelfTieZi")
    public R<?> getSelfTieZi(@RequestBody SelfTieZiDTO selfTieZiDTO){
        return cardService.getSelfTieZi(selfTieZiDTO);
    }
    @PostMapping("/getSelfPicture")
    public R<?> getSelfPicture(@RequestBody SelfTieZiDTO selfTieZiDTO){
        return cardService.getSelfPicture(selfTieZiDTO);
    }

    @PostMapping("/GetTieZiInfo/{cardId}")
    @ApiResponse(description = "帖子的详情页面")
    public R<?> GetTieZiInfo(@PathVariable int cardId,HttpServletRequest request){
        Long Uid = Long.parseLong(request.getSession().getAttribute("UserId").toString());
        return cardService.getTieZiInfo(cardId,Uid);
    }



}
